//
//  AccountApi.swift
//  Exam-iOS
//
//  Created by lishengfeng on 2018/3/10.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import Moya

enum ShurenApi {
    ///登录
    case login(mobile: String, password: String)
    ///获取用户信息
    case userInfo
    ///获取图片上传信息
    case getUploadUrl
    ///软件使用说明
    case softInstruction
    ///新闻列表
    case newsList(pageNum: Int)
    ///新闻详情
    case newsDetail(newsId: Int)
    ///金币列表
    case productCoins
    ///反馈
    case feedback(content: String)
    ///支付验证
    case coinCertificate(receipt: String, chooseEnv: Int, productId: String, quantity: Int)
    ///支付历史
    case purchaseHistory
}

extension ShurenApi: LSFTargetType {
    var path: String {
        switch self {
        case .login:
            return "login"
        case .userInfo:
            return "user/info"
        case .getUploadUrl:
            return "user/get-upload-url"
        case .softInstruction:
            return "news/soft-instruction"
        case .newsList:
            return "news/list"
        case .newsDetail:
            return "news/detail"
        case .productCoins:
            return "product/coins"
        case .feedback:
            return"user/feedback"
        case .coinCertificate:
            return "iap/certificate"
        case .purchaseHistory:
            return "user/purchase-history"
        }
    }
    
    var paramaters: [String : Any]? {
        switch self {
        case .login(let mobile, let password):
            return ["mobile": mobile,
                    "password": password]
            
        case .newsDetail(let newsId):
            return ["newsId": newsId]
            
        case .newsList(let pageNum):
            return ["pageNum": pageNum]
        case .feedback(let content):
            return ["content": content]
        case .coinCertificate(let receipt, let chooseEnv, let productId, let quantity):
            return ["receipt": receipt,
                    "chooseEnv": chooseEnv,
                    "productId": productId,
                    "quantity": quantity]
        case .userInfo, .getUploadUrl, .softInstruction, .productCoins, .purchaseHistory:
            return nil
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .login, .getUploadUrl, .feedback, .coinCertificate:
            return .post
            
        case .userInfo, .softInstruction, .newsList, .newsDetail, .productCoins, .purchaseHistory:
            return .get
        }
    }
}

let shurenProvider = LSFMoyaProvider<ShurenApi>.provider()
let shuren60Provider = LSFMoyaProvider<ShurenApi>.provider(60)


